//
//  MHComicPictureViewController.m
//  ManHua
//
//  Created by 赵永泉 on 15/10/26.
//  Copyright © 2015年 蓝欧科技. All rights reserved.
//

#import "MHComicPictureViewController.h"
#import "MHComicPictureCell.h"
#import <AFNetworking.h>

@interface MHComicPictureViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *pictureURLArray;

@end

@implementation MHComicPictureViewController

- (void)setEpisode:(MHComicEpisode *)episode
{
    _episode = episode;
    NSDictionary *dict = [NSDictionary dictionaryWithObjects:@[@"picturelist", [NSString stringWithFormat:@"%ld", episode.SectionID]] forKeys:@[@"method", @"sectionid"]];
    [[AFHTTPRequestOperationManager manager] GET:@"http://112.124.96.190:9090/bukamanhua5appjobs/ComicHandle.ashx" parameters:dict success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        self.pictureURLArray = [NSMutableArray array];
        for (NSDictionary *dict in responseObject) {
            [self.pictureURLArray addObject:dict[@"PictureURL"]];
        }
        [self.tableView reloadData];
    } failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error) {
        NSLog(@"%@", error.localizedDescription);
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor =[UIColor whiteColor];
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, Height - 20, Width)];
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.transform = CGAffineTransformMakeRotation(-M_PI / 2);
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.center = CGPointMake(Width * 0.5, Height * 0.5);
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.rowHeight = 297.0 / 210.0 * Height + 10;
    [self.tableView registerClass:[MHComicPictureCell class] forCellReuseIdentifier:@"picture"];
}

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.pictureURLArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MHComicPictureCell *cell = [tableView dequeueReusableCellWithIdentifier:@"picture" forIndexPath:indexPath];
    cell.picturURL = self.pictureURLArray[indexPath.row];
    return cell;
}
@end
